package day09.CollectionsTest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Test1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(
                list, "3", "7", "12", "2", "18", "1", "16", "9", "37", "4");
        System.out.println(list);
        Collections.sort(list);
        System.out.println(list);
        /*
        sort()方法, 可以使用一个比较器对象
        来对数据大小进行比较
         */
//        Collections.sort(list, new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                int a = Integer.parseInt(o1);
//                int b = Integer.parseInt(o2);
//                return a - b;
//            }
//        });
        Collections.sort(list,(String o1, String o2) -> {
                int a = Integer.parseInt(o1);
                int b = Integer.parseInt(o2);
                return a - b;
        });

        System.out.println(list);


    }
}
